package com.tacademy.jmtwitter;

import java.util.ArrayList;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TimelineAdapter extends ArrayAdapter<Status> {
	ArrayList<Status> mDataList;
	Context mContext;
	public TimelineAdapter(Context context, ArrayList<Status> statuses) {
		super(context, 0, statuses);
		mDataList = statuses;
		mContext = context;
	}



	@Override
	public View getView(int position, View convertView, ViewGroup parent) {// 가장
																			// 중요!!converView
																			// >>들어오면
																			// 재활용가능>>디폴트값
																			// 없음
																			// 다
																			// 채워줘야함
		// 1. View 생성
		//
		View v;
		ViewHolder holder;
		if (convertView == null) {
			LayoutInflater inflater = LayoutInflater.from(getContext());
			v = inflater.inflate(R.layout.item_linear, parent, false);
			holder = new ViewHolder();
			holder.text = (TextView) v.findViewById(R.id.itemText);
			holder.create_at = (TextView) v.findViewById(R.id.itemCreateAt);
			holder.screen_name = (TextView) v.findViewById(R.id.itemScreenName);
			holder.name = (TextView) v.findViewById(R.id.itemName);
			holder.imageview = (ImageView) v.findViewById(R.id.imageView1);
			v.setTag(holder);// ?????
		} else {
			v = convertView;
			holder = (ViewHolder) v.getTag();
		}
		// 2 View 데이터 넣어주기

		holder.text.setText(mDataList.get(position).getText());
		holder.create_at.setText(mDataList.get(position).getCreate_at());
		holder.screen_name.setText(mDataList.get(position).user.getName());
		holder.name.setText("@"+mDataList.get(position).user.getScreen_name());
		holder.imageview.setImageResource(R.drawable.ic_lock_airplane_mode);
		if (mDataList.get(position).user.getProfile_image_bm() != null) {
			holder.imageview.setImageBitmap(mDataList.get(position).user.getProfile_image_bm());
		} else {
			holder.imageview.setImageResource(R.drawable.ic_lock_airplane_mode);// 디폴트값
																				// 무조건
																				// 지정해줘야함!!!!!!!!!
		}

		return v;
	}

	static class ViewHolder {
		TextView text, create_at, screen_name, name;
		ImageView imageview;

	}
	

}
